export interface columnType {
    key: string,
    title: string,
    width?: number,
    type?: string,
    fixed?: string,
    children?: any
}

export interface tableDate {
    number: string,
    name: string,
    startTime: string,
    endTime: string
}

export const mergeColumn = 'number';

export const defaultColumnType = 'month';

export const size = 'default';
export const defaultColumn: Array<columnType> = [
    {
        key: 'number',
        title: '资产编号',
        fixed: 'left',
        width: 100
    },
    {
        key: 'name',
        title: '任务描述',
        fixed: 'left',
        width: 250
    },
    {
        key: 'startTime',
        title: '开始时间',
        type: 'date',
        width: 120
    },
    {
        key: 'endTime',
        title: '结束时间',
        type: 'date',
        width: 120
    }
];

export const loadingSvg = `
        <path class="path" d="
          M 30 15
          L 28 17
          M 25.61 25.61
          A 15 15, 0, 0, 1, 15 30
          A 15 15, 0, 1, 1, 27.99 7.5
          L 15 15
        " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>`;

export const rowBackColor = ['#33ffaa', '#33ffff', '#33ff33'
    , '#FFFF00', '#ffcc22', '#ccff99'];

let useColorRecord: any = {};
export function randomColor() {
    rowBackColor.forEach(item => {
        useColorRecord[item] = 0;
    })
    return realRandomColor;
}

function realRandomColor() {
    // @ts-ignore
    let min = Math.min(...Object.values(useColorRecord));
    // @ts-ignore
    for (let item in useColorRecord) {
        if (min === useColorRecord[item]) {
            useColorRecord[item]++;
            return item;
        }
    }
}

const defaultStartHour = 9;
const defaultEndHour = 18;
export function getDefaultRangeTime(startHour = defaultStartHour, endHour = defaultEndHour) {
    let year = new Date().getFullYear();
    let month = new Date().getMonth() + 1;
    let day = new Date().getDate();
    return [
        new Date(year, month, day, startHour, 0, 0),
        new Date(year, month, day, endHour, 0, 0)
    ];
}

export function dateFormat(date: any, type = 'day', suffix = '/') {
    date = new Date(date);
    return type === 'month' ? `${date.getFullYear()}${suffix}${(date.getMonth() + 1).toString().padStart(2, '0')}`
            : `${date.getFullYear()}${suffix}${(date.getMonth() + 1).toString().padStart(2, '0')}${suffix}${date.getDate().toString().padStart(2, '0')}`
}

export function getWeekDates (date = new Date().getTime()) {
    let today = new Date(date);
    let day = today.getDay();
    let year = today.getFullYear();
    let month = today.getMonth();
    let dayDate = today.getDate();
    let startDate: Date;
    let endDate: Date;
    if (day == 0) {
        startDate = new Date(year, month, dayDate - day - 6);
        endDate = new Date(year, month, dayDate - day);
    } else {
        startDate = new Date(year, month, dayDate - day + 1);
        endDate = new Date(year, month, dayDate - day + 7);
    }
    return {startDate: dateFormat(startDate, 'day', '-'), endDate: dateFormat(endDate, 'day', '-')};
}
